home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
aztcmtsk.arc
/
AZTASK.CRT
next >
Wrap
Text File
|
1986-03-24
|
3KB
|
139 lines
/* Copyright (C) 1981,1982 by Manx Software Systems */
/* Copyright (C) 1982 Thomas Fenwick */
/* edited 8/21/85 by DECortesi in order to:
1. allow " specials and blanks" in argv tokens,
2. eliminate attempted unlink of $$$.SUB on
normal program exit (i.e. termination of
main() without an explicit return(code)),
3. extend exit(code) to check for CP/M PLUS and,
if found, to set the program return code
and to cancel submit files its way,
4. fix abysmal performance of redirected output
with an insertion from James Apedaile.
*/
/* edited 3/86 by DECortesi to make into TROOT.C, a tasking
CROOT. Croot() now sets up main(argc,argv) as a task
with a stack of 256 words, invoked by calling defer().
3/13/86 correct order of main() arguments
*/
#include "errno.h"
#include "fcntl.h"
#include "io.h"
#include "stdio.h" /* added by Apedaile fix */
/*
channel table: relates fd's to devices
*/
badfd()
{
errno = EBADF;
return -1;
}
noper()
{
return 0;
}
struct channel chantab[] = {
{ 2, 0, 1, 0, noper, 2 },
{ 0, 2, 1, 0, noper, 2 },
{ 0, 2, 1, 0, noper, 2 },
{ 0, 0, 0, 0, badfd, 0 },
{ 0, 0, 0, 0, badfd, 0 },
{ 0, 0, 0, 0, badfd, 0 },
{ 0, 0, 0, 0, badfd, 0 },
{ 0, 0, 0, 0, badfd, 0 },
{ 0, 0, 0, 0, badfd, 0 },
{ 0, 0, 0, 0, badfd, 0 },
{ 0, 0, 0, 0, badfd, 0 },
};
#define MAXARGS 30
static char *Argv[MAXARGS];
static char Argbuf[128];
static int Argc;
exit(code) /* extensively revised */
{
register int sysno;
static int killget = 0x81;
closall_();
if ( code ) {
sysno = bdos(12,0);
if (sysno < 0x0030) /* CP/M 2.2 or less */
unlink("A:$$$.SUB"); /* cancel submit */
else if (sysno < 255)
{ /* CP/M Plus */
bdos(108,code); /* set program retcode */
bdos(60,&killget); /* kill GET rsx */
} /* else MP/M */
}
boot_();
}
extern main();
Croot()
{
register char *cp, *fname;
register int k;
blockmv(Argbuf, (char *)0x81, 127);
Argbuf[*(char *)0x80 & 0x7f] = 0;
Argv[0] = "";
cp = Argbuf;
Argc = 1;
while (Argc < MAXARGS) {
while (*cp == ' ' || *cp == '\t')
++cp;
if (*cp == 0)
break;
if (*cp == '>') { /* redirect output */
k = 1;
goto redirect;
} else if (*cp == '<') { /* redirect input */
k = 0;
redirect:
while (*++cp == ' ' || *cp == '\t')
;
fname = cp;
while (*++cp)
if (*cp == ' ' || *cp == '\t') {
*cp++ = 0;
break;
}
close(k);
if (k)
{
/* inserted by Apedaile */ Cbuffs[k]._buflen = BUFSIZ;
k = creat(fname, 0666);
}
else
k = open(fname, O_RDONLY);
if (k == -1) {
strcpy(0x80, "Can't open file for redirection: ");
strcat(0x80, fname);
strcat(0x80, "\n");
write(2, 0x80, strlen(0x80));
exit(10);
}
/* new case */ } else if (*cp == '\"') {
/* inserted to */ Argv[Argc++] = cp+1;
/* handle quoted */ while (*++cp)
/* tokens: take */ if (*cp=='\"') {
/* all of token up to */ *cp++ = 0;
/* closing quote or end */ break;
/* of line */ }
} else {
Argv[Argc++] = cp;
while (*++cp)
if (*cp == ' ' || *cp == '\t') {
*cp++ = 0;
break;
}
}
}
maketask(&main,256,2,Argc,Argv); /* sets up main task */
defer(); /* invokes it, no return */
}